<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    window.onload = function() {
        var user = document.getElementById('user');
        user.onblur = function() {
            var user = document.getElementById('user');
            var username = user.value; // 获取用户名
            var pwd = document.getElementById('pwd').value;
            // alert("gh");
            // 创建对象：
            var xhr = null;
            if (window.XMLHttpRequest) {
                xhr = new XMLHttpRequest();
            } else {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            // 准备发送
            var parm = "user=" + username + "&password=" + pwd;
            xhr.open("get", './lianxiGET.php?' + encodeURI(parm));
            // 执行发送
            xhr.send(null);
            // 执行回调函数
            xhr.onreadystatechange = function() {
                if (xhr.readystate == 4) {
                    // 200 代表响应成功
                    if (xhr.status == 200) {
                        console.log(xhr.responseText);
                        document.getElementById('span').innerHTML = xhr.responseText;
                    }
                }
            }
        }

    }
</script>

<body>
    <form action="">
        用户: <input type="text" name="username" id="user"><span id="span"></span><br> 密码: <input type="text" name="pwd" id="pwd"><br>
        <input type="submit" id='btn' value='登录'>

    </form>
</body>

</html>